//引入工具类
const util = require('../../utils/util');
// 加载配置文件
const config = require('../../utils/config');

const app = getApp()

Page({
    data: {
        userInfo: {},
        accountInfo: {},
        visible: false
    },
    callPhone() {
        wx.makePhoneCall({
            phoneNumber: this.data.accountInfo.phone
        })
    },
    handleClose() {
        this.setData({
            visible: false
        });
    },
    handleOk() {
        this.setData({
            visible: false
        });
        this.goLogout();
    },
    goNav() {
        wx.openLocation({
            latitude: this.data.accountInfo.company.latitude,
            longitude: this.data.accountInfo.company.longitude,
            scale: 12,
            name: this.data.accountInfo.company.name,
            address: this.data.accountInfo.company.address
        })
    },

    onLoad: function(options) {
        this.setData({
            userInfo: app.globalData.userInfo
        })
        wx.showLoading({
            title: '加载中...'
        })
        let _this = this;
        app.ajax({
            url: `${config.httpUrl}log/findMemberInfo`,
            method: 'get',
            callback: function(error, data) {
                wx.hideLoading();
                console.log(data)
                _this.setData({
                    accountInfo: data.data
                });
            }
        })
    },
    goUnbind() {
        this.setData({
            visible: true
        });
    },
    goLogout() {
        wx.showLoading({
            title: '解绑中...'
        })
        let _this = this;
        app.ajax({
            url: `${config.httpUrl}log/cancelBinding`,
            method: 'post',
            data: {
                userName: _this.data.accountInfo.name
            },
            callback: function(error, data) {
                wx.hideLoading();
                let url = '/pages/login/login'
                wx.reLaunch({
                    url
                });
            }
        })
    },
    handleClick() {
        console.log("在线客服")
    },
    onShow() {
        let pages = getCurrentPages();
        let curPage = pages[pages.length - 1];
        app.checkBind(curPage.route);
    }
})